package search;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class SearchResponse {
    private Data data;
    private String message;
    private int resultCode;

    public static class Data {
        private int currPage;
        private List<Product> list;  // 改为单层列表
        private int pageSize;
        private int totalCount;
        private int totalPage;

        // 处理嵌套列表的setter
        public void setList(List<List<Product>> nestedList) {
            this.list = new ArrayList<>();
            if (nestedList != null) {
                for (List<Product> subList : nestedList) {
                    if (subList != null) {
                        this.list.addAll(subList);
                    }
                }
            }
        }

        // Getters
        public List<Product> getList() {
            return list != null ? list : Collections.emptyList();
        }

        public int getCurrPage() {
            return currPage;
        }

        public int getPageSize() {
            return pageSize;
        }

        public int getTotalCount() {
            return totalCount;
        }

        public int getTotalPage() {
            return totalPage;
        }

        // Setters
        public void setCurrPage(int currPage) {
            this.currPage = currPage;
        }

        public void setPageSize(int pageSize) {
            this.pageSize = pageSize;
        }

        public void setTotalCount(int totalCount) {
            this.totalCount = totalCount;
        }

        public void setTotalPage(int totalPage) {
            this.totalPage = totalPage;
        }
    }

    // Getters and Setters
    public Data getData() {
        return data;
    }

    public void setData(Data data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getResultCode() {
        return resultCode;
    }

    public void setResultCode(int resultCode) {
        this.resultCode = resultCode;
    }
}